package cn.lijida.weiwei.favor.modules.home.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.lijida.weiwei.favor.modules.home.entity.FavorHome;
import cn.lijida.weiwei.favor.modules.home.mapper.FavorHomeMapper;
import cn.lijida.weiwei.favor.modules.home.service.IFavorHomeMemberService;
import cn.lijida.weiwei.favor.modules.home.service.IFavorHomeService;

/**
 * <p>
 * 家庭 服务实现类
 * </p>
 *
 * @author jobob
 * @since 2019-12-28
 */
@Service
public class FavorHomeServiceImpl extends ServiceImpl<FavorHomeMapper, FavorHome> implements IFavorHomeService {
	
	@Autowired
	private IFavorHomeMemberService homeMemberService;

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void create(FavorHome home,Long loginId) throws Exception {
		
		//创建家庭
		home.setCreateMember(loginId);
		home.setManageMember(loginId);
		
		boolean status = this.save(home);
		if(!status){
			throw new Exception("创建家庭失败");
		}
		
		//创建者加入家庭
		homeMemberService.join(home.getHomeId(),loginId);
	}

	@Transactional(rollbackFor = Exception.class)
	public void join(Long homeId, Long loginId) {
		
	}

}
